<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="css/index.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){

            // 移到留言上可以删除,编辑-------------------------------------------
            $('#mian .list .onep').hover(function() {
                $(this).find('a').show();
                $(this).find('.edit_a').show();
                $(this).find('.content').addClass('content1');
            }, function() {
                $(this).find('a').hide();
                $(this).find('.edit_a').hide();
                $(this).find('.content').removeClass('content1');
            });

            // 留言方式的切换------------------------------------------------
            var c=1;
            $('.close').click(function(event) {
                if(c==1){
                    $('#right').stop().animate({"top": 800+'px'},2000).parent().parent().find('#bottom_out').stop().animate({"bottom": 0+'px'},3000);
                    c=0;
                }else{
                    $('#right').stop().animate({"top": 50+'px'},2000).parent().parent().find('#bottom_out').stop().animate({"bottom": -120+'px'},3000);
                    c=1;
                }
            });



        })


    </script>

</head>

<body>
<div id="top">
    <h1>留言板</h1>
</div>

<div id="mian_out">
    <div id="mian">
        <h2>其它人都说了什么</h2>
        <ul class="list">
            <?php
            include 'config.php';
            $sql = 'select * from think_data ';
            $result=mysql_query($sql,$link);
            while($rows=mysql_fetch_array($result)){
                ?>
                <li class="onep">
                    <p class="pic"><img src="<?php echo $rows['imgurl'];?>" alt="" /></p>
                    <p class="name"><?php echo $rows['username'];?></p>
                    <p class="content"><?php echo $rows['message'];?>
                        <span> (来自火星"<?php echo $rows['sex'];?>侠"的留言)</span>
                    </p>
                    <a class="edit_a" href="javascript:" onclick="if(confirm('确定修改吗？')) location.href='update.php?id=<?php echo $rows['id'];?>'" >修改</a>
                    <a class="delete" href="javascript:" onclick="if(confirm('确定删除吗？')) location.href='del.php?id=<?php echo $rows['id'];?>'" >删除</a>
                </li>
                <?php
            }
            ?>
        </ul>
    </div>


    <?php
        $id=$_GET['id'];
        $sql="select * from think_data where id=".$id;
        $result=mysql_query($sql,$link);
        while($rows=mysql_fetch_array($result)){
    ?>

    <div id="right">
        <h2>留下你的脚步吧</h2>
        <form action="" method="post">
            <p class="one">
                昵称:<input class="name" name="username" type="text" placeholder="你的名字" />
            <?php
            if($rows['sex']==='男') {
                ?>
                <input type="radio" name="sex" value="男" checked="checked"/>男侠
                <input type="radio" name="sex" value="女"/>女侠
                <?php
            }else {
                ?>
                <input type="radio" name="sex" value="男" />男侠
                <input type="radio" name="sex" value="女" checked="checked"/>女侠
                <?php
            }
            ?>
            </p>
            <p><textarea name="message" placeholder="这个人很懒,什么都没有写"><?php echo $rows['message'];?></textarea></p>
            <p class="tow">
                <?php
                if($rows['imgurl']=="images/1.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" checked="checked"/><img src=" images/1.jpg"
                                                                                                   alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/2.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                                   alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg" checked="checked"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/2.jpg") {
                ?>
                <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                               alt=""/>
                <input type="radio" name="imgurl" value="images/2.jpg" checked="checked"/><img src=" images/2.jpg" alt=""/>
                <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                <?php
                }elseif($rows['imgurl']=="images/3.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                                   alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg" checked="checked"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/4.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                                   alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg" checked="checked"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }
                ?>
            </p>
            <p class="thr"><input class="btn" type="submit" value="提交"/></p>
        </form>
        <div class="close"></div>
    </div>

</div>

<div id="bottom_out">
    <div id="bottom">
        <form action="" method="post">
            <p class="one">
                昵称:<input class="name" name="username" type="text" placeholder="大爷你的名字"/>
                <br/><br/>
                <?php
                    if($rows['sex']==='男') {
                        ?>
                        <input type="radio" name="sex" value="男" checked="checked"/>男侠
                        <input type="radio" name="sex" value="女"/>/>女侠
                        <?php
                    }else {
                        ?>
                        <input type="radio" name="sex" value="男" />男侠
                        <input type="radio" name="sex" value="女" checked="checked"/>女侠
                        <?php
                    }
                ?>
            </p>
            <p><textarea name="message" placeholder="这个人很懒,什么都没有写"></textarea></p>
            <p class="tow">
                <?php
                if($rows['imgurl']=="images/1.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" checked="checked"/><img src=" images/1.jpg"
                                                                                                   alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/2.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                  alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg" checked="checked"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/2.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                  alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg" checked="checked"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/3.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                  alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg" checked="checked"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }elseif($rows['imgurl']=="images/4.jpg") {
                    ?>
                    <input type="radio" name="imgurl" value="images/1.jpg" /><img src=" images/1.jpg"
                                                                                  alt=""/>
                    <input type="radio" name="imgurl" value="images/2.jpg"/><img src=" images/2.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/3.jpg"/><img src=" images/3.jpg" alt=""/>
                    <input type="radio" name="imgurl" value="images/4.jpg" checked="checked"/><img src=" images/4.jpg" alt=""/>
                    <?php
                }
                ?>
            </p>
            <p class="thr"><input class="btn" type="submit" value="提交"/></p>
        </form>
        <div class="close"></div>
    </div>
</div>
<?php
}

if($_POST){
    $username=$_POST['username'];
    $sex=$_POST['sex'];
    $message=$_POST['message'];
    $imgurl=$_POST['imgurl'];
    $sql="UPDATE think_data SET username = '{$username}',sex='{$sex}',message='{$message}',imgurl='{$imgurl}' WHERE id={$id}";
    if  (mysql_query($sql,$link))
    {
        echo "<script> alert('提交成功');parent.location.href='index.php'; </script>";
    }
    else
    {

        echo "<script> alert('提交失败');parent.location.href='index.php'; </script>";
        echo $sql;
    }
}
?>
</body>
</html>
